package com.itheima.d2_reflect;

import org.junit.Test;

import java.lang.reflect.Constructor;

public class Test2Constructor {
    @Test
    public void testGetConstructors(){
        Class c =Cat.class;
        Constructor[] constructors = c.getDeclaredConstructors();

        for (Constructor constructor : constructors) {
            System.out.println(constructor.getName()+"====>"+
                    constructor.getParameterCount());
        }
    }
    @Test
    public void testGetConstructor() throws Exception {
        Class c =Cat.class;

        Constructor constructor1 = c.getDeclaredConstructor();
        System.out.println(constructor1.getName()+"==>"+
                constructor1.getParameterCount());
        constructor1.setAccessible(true);
        Cat cat =(Cat)constructor1.newInstance();
        System.out.println(cat);

        Constructor constructor2 = c.getDeclaredConstructor(String.class,int.class);
        System.out.println(constructor2.getName()+"==>"+constructor2.getParameterCount());
        constructor2.setAccessible(true);
        Cat cat2 =(Cat) constructor2.newInstance("叮当猫",3);
        System.out.println(cat2);
    }


}
